home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Merciful 2
/
Merciful - Disc 2.iso
/
software
/
l
/
lightwave3dv3.5a.dms
/
lightwave3dv3.5a.adf
/
lw1.lha
/
arexx_examples
/
lwm
/
LWEnvelope.lwm
< prev
next >
Wrap
Text File
|
1993-06-09
|
4KB
|
180 lines
/* CMD: LW Envelope
* Make envelope file for LightWave 3D
* By Arnie Cachelin © 1992 NewTek Inc.
*/
NUMERIC DIGITS 8
call addlib "LWModelerARexx.port", 0
call addlib "rexxsupport.library", 0, -30, 0
signal on error
signal on syntax
MATHLIB="rexxmathlib.library"
IF POS(MATHLIB , SHOW('L')) = 0 THEN
IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
call notify(1,"!Can't find "MATHLIB)
exit
END
frames = 120
fn = 1
fun ="2*exp(-2*t)*(1+sin(5*t))"
w = 5
st = 2
d=0
KeySpacing =5
sysnam = 'Envelope Maker '
version = 'Envelope Maker 1.0'
filnam = 'ENV:Envelope.state'
if (exists(filnam)) then do
if (~open(state, filnam, 'R')) then break
if (readln(state) ~= version) then break
parse value readln(state) with frames fn w d st keyspacing .
fun = readln(state)
call close state
end
FnList.1='RandomWalk'
FnList.2='Oscillator'
FnList.3='Bounce'
FnList.4='Exponential'
FnList.5='Custom'
FList= FnList.1 FnList.2 FnList.3 FnList.4 FnList.5
call req_begin sysnam
id_mes = req_addcontrol("Create LW",'T',"envelopes from mathematical functions")
id_frames = req_addcontrol("Frames", 'n')
id_keysp = req_addcontrol("Key Spacing", 'n')
id_w = req_addcontrol("Frequency", 'n')
id_d = req_addcontrol("Damping", 'n')
id_st = req_addcontrol("Start Value", 'n')
id_fn = req_addcontrol('Type:','CV',FList)
id_fun = req_addcontrol("Custom f(t)", 's', 35)
call req_setval id_frames,frames
call req_setval id_Keysp,keyspacing
call req_setval id_fn, fn
call req_setval id_w, w
call req_setval id_d, d
call req_setval id_st, st
call req_setval id_fun, fun
if (~req_post()) then do
call req_end
exit
end
/* Get input from Requester */
frames = req_getval(id_frames) % 1
fn = req_getval(id_fn)
fun = req_getval(id_fun)
w = req_getval(id_w)
d = req_getval(id_d)
st = req_getval(id_st)
KeySpacing = req_getval(id_keysp)
call req_end
if (open(state, filnam, 'W')) then do
call writeln state, version
call writeln state, frames fn w d st keyspacing
call writeln state, fun
call close state
end
ENVFile=getfilename("-- Save Envelope --","envelopes")
if ENVFile ~="(none)" then File.Name=ENVFile
else exit
h=0; p=0; b=0
xsc=1; ysc=1; zsc=1
File.type="LWEN"
SecsPerFrame=1/30
Time=SecsPerFrame*Frames
Keys=1+Frames%KeySpacing
SlicesPerFrame=1 /* No need for extra slices, since f'ns are analytic not evolved */
dt=SecsPerFrame/SlicesPerFrame
frame=0
slice=0
/* Initial Conditions */
v=st
call meter_begin(frames*slicesperframe+5 , 'Generating Envelope',frames' Frames, 'Keys' Key Frames')
call WriteHeader(mot,keys)
do t=0 to Time+dt by dt
slice=slice+1
select
when fn=1 then v=RandomWalk(t)
when fn=2 then v=Oscillator(t,d)
when fn=3 then v=Bounce(t,d)
when fn=4 then v=Exponential(t)
when fn=5 then do
fnst="v="fun
interpret fnst
end
otherwise nop
end
if slice//SlicesPerFrame = 0 then do
if frame//KeySpacing=0 then
call WriteKey(mot,frame,0)
else if frame=Frames then
call WriteKey(mot,frame,0)
frame=frame+1
end
call meter_step()
end
call close mot
call meter_end()
call notify(1,'!Created LightWave Envelope File: 'File.name)
exit
syntax:
error:
t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
exit
RandomWalk: procedure expose v w st
arg t
s=st*(2*randu()-1)
return(v+s)
Oscillator: procedure expose v w st
arg t,d
return( st*0.5*(1+exp(-d*t)*sin(w*t+90*st)) )
Bounce: procedure expose v w st
arg t,d
return( st*exp(-d*t)*abs(cos(w*t)) )
Exponential: procedure expose w st
arg t
return( st*exp(w*t) )
WriteKey: PROCEDURE EXPOSE v
arg MotFile, frame, lin
channels=v
spline=frame lin "0.0 0.0 0.0"
call writeln(MotFile,channels)
call writeln(MotFile,spline)
return frame
WriteHeader: PROCEDURE EXPOSE File.
arg MotFile, Keys
if open(MotFile,File.name,'W') then do
call writeln(MotFile,File.type)
call writeln(MotFile,"1") /* magic # */
call writeln(MotFile,"1") /* Channels */
call writeln(MotFile,Keys)
end
else do
Bummer("Can't open Envelope file : "File.name)
end
return 1
Bummer:
ARG etxt
SAY "ERROR: "||RC||etxt
call end_all
exit